﻿namespace DreamBuilder.Common
{
    using System;
    using System.IO;
    using System.IO.Compression;

    public class ViewStateManager
    {
        public static byte[] Compress(byte[] data)
        {
            MemoryStream stream = new MemoryStream();
            GZipStream stream2 = new GZipStream(stream, CompressionMode.Compress);
            stream2.Write(data, 0, data.Length);
            stream2.Close();
            return stream.ToArray();
        }

        public static byte[] Decompress(byte[] data)
        {
            MemoryStream stream = new MemoryStream();
            stream.Write(data, 0, data.Length);
            stream.Position = 0;
            GZipStream stream2 = new GZipStream(stream, CompressionMode.Decompress);
            MemoryStream stream3 = new MemoryStream();
            byte[] buffer = new byte[0x400];
            while (true)
            {
                if (stream2.Read(buffer, 0, buffer.Length) <= 0)
                {
                    stream2.Close();
                    return stream3.ToArray();
                }
                stream3.Write(buffer, 0, buffer.Length);
            }
        }
    }
}

